﻿
document.addEventListener('DOMContentLoaded', function () {
    $("#link_qiang").click(function () {
        openUrl("https://mis2020.517.cn/a332_Third_YeWu/a3266_MLink/MLink.aspx?Id=");
    });
    $("#link_gxt").click(function () {
        chrome.storage.local.get({ userid: '0' }, function (ret) {
            var userid = ret["userid"];
            openUrl("https://mis.517.cn/a32_Third/a3212_MLink/Star/?userid=" + userid + "&id=");
        });
    });
    $("#link_info").click(function () {
        openUrl("https://mis2020.517.cn/a90_BaseInfo/b1099_Common/MisMLinkObject.aspx#MLinkObjId=");
    });
    $("#tfs").click(function () {
        window.open("http://tfs2019.517.jiali:8080/tpc_website/tp_WebApiMLink_2021/_versionControl?path=%24%2Ftp_WebApiMLink_2021%2Ftp_WebApiMLink%2FChromePlug-V3%2Fmanifest.json");
    });
    $("#help").click(function () {
        window.open("https://wiki.517cdn.com/index.php/MLink/product/Mlnik%E6%8F%92%E4%BB%B6%E5%8A%9F%E8%83%BD");
    });

    chrome.storage.local.get({ userid: '0' }, function (ret) {
        var userid = ret["userid"];
        $("#userid").html(userid);
    });

    let app = chrome.runtime.getManifest();
    $("#version").html(`(${app.version})`);
    ;//
});

function openUrl(url) {
    chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
        var cacheName = "mlink_" + tabs[0].id;
        chrome.storage.local.get({ [cacheName]: '0' }, function (ret) {
            var objid = ret[cacheName];
            if (objid == '0') {
                alert("没有Mlink关系哦!");
            }
            else {
                window.open(url + objid);
            }
        });
    })
}

